package com.example.springboot.controller;

import com.example.springboot.model.Customer;
import com.example.springboot.service.CustomerService;
import com.example.springboot.util.ResponseUtil;
import com.github.pagehelper.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class CustomerController {
    @Autowired private CustomerService customerService;

    /**
     * 客户列表分页
     * @param customer
     * @return
     */
    @RequestMapping("customer/list")
    public String list(Customer customer, @RequestParam(defaultValue = "0") Integer pageNum, @RequestParam(defaultValue = "10" ) Integer pageSize){
       Page<List<Customer>> page= customerService.getListPage(customer,pageNum,pageSize);
        return ResponseUtil.getSuccess(page.getResult(),page.getTotal());
    }

    @RequestMapping("customer/saveOrUpdate")
    public void saveOrUpdate(Customer customer){
         customerService.saveOrUpdate(customer);
    }

    @RequestMapping("customer/del")
    public void del(Long id){
        customerService.del(id);
    }
}
